package cn.edu.scau.cmi.zengGuanSheng.singleton;

public class Chairman {
	private static Chairman instance;
	private String name;
	private int flag = -1;
	//
	private Chairman(String name) {
		this.name = name;
	}
	public static Chairman getInstance(String name) {
		if(instance==null) {
			if(!name.equals(null)&&name=="毛泽东") {
				instance = new Chairman(name);
				instance.setFlag(1);
				System.out.println("创建的主席对象是毛泽东");
				return instance;
			}
			else {
				instance = new Chairman("毛泽东");
				instance.setFlag(0);
				System.out.println("创建的主席对象不能是"+name+",只能是毛泽东");
				return instance;
			}
		}
		instance.setFlag(0);
		System.out.println("主席对象只能有一个,那就是毛泽东");
		return instance;
	}
	
	
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return this.name;
	}
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	
	

}
